package edu.gmu.messages;
public class EndPoint implements edu.gmu.middleware.Message{
    public String address;
    public int port;
    
    public EndPoint()
    {
    
    }
    
    public EndPoint( String address, int port )
    {
        this.address = address;
        this.port    = port;
    }
    
    public boolean equals( Object obj )
    {
        if( obj == this ) return true;
        
        if( !(obj instanceof EndPoint) ) return false;
        EndPoint o = (EndPoint)obj;
        
        return  o.address.equals(this.address) &&
                o.port == this.port;
    }

    public void marshal(edu.gmu.streams.BlockOutputStream output) throws java.io.IOException{
        output.writeUTF(address);
        output.writeInt(port);
    }

    public void unmarshal(edu.gmu.streams.BlockInputStream input) throws java.io.IOException{
        this.address = input.readUTF();
        this.port    = input.readInt(); 
    }
    
    public String toString()
    {
        return"address=" + this.address + " port=" +this.port;
    }
    
    
    
    //------------------------------------------------------------------------//
    // Static utilities
    //------------------------------------------------------------------------//
    
    public static final String WELL_KNOWN_ADDRESS  = "cs675-";
    public static final String WELL_KNOWN_SUFFIX   = ".vsnet.gmu.edu";
    
    /**
     * Gets the hostAddress of this server.
     * @return
     */
    public static EndPoint deriveHostAddress( int physicalAddress )
    {
        return new EndPoint( WELL_KNOWN_ADDRESS+physicalAddress+WELL_KNOWN_SUFFIX, physicalAddress*10000 );
//        return new EndPoint( "localhost", physicalAddress*10000 );
    }
}
